﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> Public Class MaxTalbeGroups
    Private m_MaxTableAerageTime(-1) As MaxTalbeAerageTime
    Property MaxTableAerageTime() As MaxTalbeAerageTime()
        Get
            Return Me.m_MaxTableAerageTime
        End Get
        Set(ByVal value As MaxTalbeAerageTime())
            Me.m_MaxTableAerageTime = value
        End Set
    End Property
    Public Function GetData(ByVal strAERMODOUT As String(), ByVal Receptor As Receptor, ByVal IsDep As Boolean, ByVal AerageTime As AerageingTime, ByVal nMax As Integer, ByVal strGroup As String, ByVal IsAnalisis As Boolean, ByVal GroupSourceCount As Integer, ByVal version As String)
        If AerageTime.H1 = True Then

            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime
            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, " 1-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H2 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, " 2-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H3 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime

            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, " 3-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H4 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime


            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, " 4-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H6 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime

            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, " 6-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H8 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime

            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, " 8-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H12 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime

            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, "12-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.H24 = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime

            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, "24-HR", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        If AerageTime.Month = True Then
            ReDim Preserve m_MaxTableAerageTime(m_MaxTableAerageTime.Length)
            m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1) = New MaxTalbeAerageTime

            '计算区域前n最大值
            If m_MaxTableAerageTime(m_MaxTableAerageTime.Length - 1).MaxTalbeResult.GetMaxTalbeDateFromAERMODOUT(strAERMODOUT, nMax, IsDep, "MONTH", strGroup, GroupSourceCount, version) = False Then
                Return False
            End If
        End If
        'If AerageTime.Period = True Then
        '    Return GetPeriodMaxTalbeResult(strAERMODOUT, Receptor, IsDep, AerageTime, nMax, strGroup, IsAnalisis)
        'End If
        Return True
    End Function
    'Public Function GetPeriodMaxTalbeResult(ByVal strAERMODOUT As String(), ByVal Receptor As Receptor, ByVal IsDep As Boolean, ByVal AerageTime As AerageingTime, ByVal OutPutOption As OutPuts, ByVal strGroup As String, ByVal IsAnalisis As Boolean) As Boolean
    '    '由于期间平均不能输出所有点前n大值，所以需要把所有点的期间平均均进行排序，然后输出前n个值。
    '    Try
    '        Dim MaxTalbeResult As New MaxTalbeResult
    '        For i As Integer = 0 To Receptor.GridCart.Ynum - 1
    '            For j As Integer = 0 To Receptor.GridCart.Xnum - 1
    '                ReDim Preserve MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length)
    '                MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1) = New ResultCon
    '                MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).con = Me.m_PeriodNameAndData.GridCon(i, j).con
    '                MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).x = Receptor.GridCart.Xinit + Receptor.GridCart.Xdelta * j
    '                MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).y = Receptor.GridCart.Yinit + Receptor.GridCart.Ydelta * (Receptor.GridCart.Ynum - 1 - i)
    '            Next
    '        Next
    '        '添加嵌套网格点的数据
    '        For k As Integer = 0 To Receptor.SubGridCart.Length - 1
    '            If Receptor.SubGridCart(k).Selected = True Then
    '                For i As Integer = 0 To Receptor.SubGridCart(k).Ynum - 1
    '                    For j As Integer = 0 To Receptor.SubGridCart(k).Xnum - 1
    '                        ReDim Preserve MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length)
    '                        MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1) = New ResultCon
    '                        MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).con = Me.m_PeriodNameAndData.SubGridCon(k)(i, j).con
    '                        MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).x = Receptor.SubGridCart(k).Xinit + Receptor.SubGridCart(k).Xdelta * j
    '                        MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).y = Receptor.SubGridCart(k).Yinit + Receptor.SubGridCart(k).Ydelta * (Receptor.SubGridCart(k).Ynum - 1 - i)
    '                    Next
    '                Next
    '            End If
    '        Next
    '        For i As Integer = 0 To Receptor.DiscCarts.Length - 1
    '            ReDim Preserve MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length)
    '            MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1) = New CAermod.ResultCon
    '            MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).con = Me.m_PeriodNameAndData.DiscCon(i).con
    '            MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).x = Me.m_PeriodNameAndData.DiscCon(i).x
    '            MaxTalbeResult.MaxCon(MaxTalbeResult.MaxCon.Length - 1).y = Me.m_PeriodNameAndData.DiscCon(i).y
    '        Next
    '        '对所有点的浓度进行排序
    '        If MaxTalbeResult.MaxCon.Length >= 2 Then
    '            For i As Integer = MaxTalbeResult.MaxCon.Length - 1 To 1 Step -1
    '                For j As Integer = MaxTalbeResult.MaxCon.Length - 1 To MaxTalbeResult.MaxCon.Length - 1 - i + 1 Step -1
    '                    If MaxTalbeResult.MaxCon(j).con > MaxTalbeResult.MaxCon(j - 1).con Then
    '                        Dim ResultCon As New CAermod.ResultCon
    '                        ResultCon.con = MaxTalbeResult.MaxCon(j).con
    '                        ResultCon.dateD = MaxTalbeResult.MaxCon(j).dateD
    '                        ResultCon.x = MaxTalbeResult.MaxCon(j).x
    '                        ResultCon.y = MaxTalbeResult.MaxCon(j).y

    '                        MaxTalbeResult.MaxCon(j).con = MaxTalbeResult.MaxCon(j - 1).con
    '                        MaxTalbeResult.MaxCon(j).dateD = MaxTalbeResult.MaxCon(j - 1).dateD
    '                        MaxTalbeResult.MaxCon(j).x = MaxTalbeResult.MaxCon(j - 1).x
    '                        MaxTalbeResult.MaxCon(j).y = MaxTalbeResult.MaxCon(j - 1).y

    '                        MaxTalbeResult.MaxCon(j - 1).con = ResultCon.con
    '                        MaxTalbeResult.MaxCon(j - 1).dateD = ResultCon.dateD
    '                        MaxTalbeResult.MaxCon(j - 1).x = ResultCon.x
    '                        MaxTalbeResult.MaxCon(j - 1).y = ResultCon.y
    '                    End If
    '                Next
    '                If MaxTalbeResult.MaxCon.Length - 1 - i >= OutPutOption.MaxTable.nMax - 1 Then
    '                    ReDim Preserve MaxTalbeResult.MaxCon(OutPutOption.MaxTable.nMax - 1)
    '                    Exit For
    '                End If
    '            Next
    '        End If
    '        Me.m_PeriodMaxTalbeResult = MaxTalbeResult
    '        Return True
    '    Catch ex As Exception
    '        Return False
    '    End Try
    'End Function
End Class
